package a03_哈希;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * <p>
 * a03_两个数组的交集复习6
 * </p>
 *
 * @author flyduck
 * @since 2025/4/15
 */
public class a03_两个数组的交集复习6 {
    public int[] intersection(int[] nums1, int[] nums2) {
        Set<Integer> set1 = new HashSet<>();
        Set<Integer> set2 = new HashSet<>();
        for (int i = 0; i < nums1.length; i++) {
            set1.add(nums1[i]);
        }

        for (int i = 0; i < nums2.length; i++) {
            if(set1.contains(nums2[i])){
                set2.add(nums2[i]);
            }
        }
        return set2.stream().mapToInt(i -> i).toArray();
    }
}
